﻿<Window x:Class="DaphneForms.PDNFilterForm"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:ignore="http://www.ignore.com"
        xmlns:loc="http://schemas.tomer.com/winfx/2006/xaml/presentation"       
        mc:Ignorable="d ignore"
        Width="640" Height="480" ResizeMode="NoResize"
        WindowStartupLocation="CenterScreen"
        Title="{loc:Translate Default='Advanced search filter'}"
        >
    <Window.Resources>
        <Style TargetType="{x:Type DatePickerTextBox}">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate>
                        <TextBox x:Name="PART_TextBox"
     Text="{Binding Path=SelectedDate, StringFormat='yyyy.MM.dd', 
     RelativeSource={RelativeSource AncestorType={x:Type DatePicker}}}" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*" />
            <ColumnDefinition Width="1*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        
        <!-- Left pane with the list of PDN tags -->
        <Grid Grid.Column="0" Grid.Row="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <DataGrid Grid.Row="0" ItemsSource="{Binding Path=PDNKeyList, Mode=OneWay, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="False"
                      CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="False"
                      SelectionMode="Single" IsReadOnly="True"  CanUserReorderColumns="False"    
                      SelectedValue="{Binding Path=SelectedKey, Mode=TwoWay}"
                      IsSynchronizedWithCurrentItem="True"
                      x:Name="uxDataGrid"
                      >
                <DataGrid.Columns>
                    <DataGridTextColumn Binding="{Binding Path=Key}" Width="1*" Header="{loc:Translate Default='PDN Key'}" />
                    <DataGridTextColumn Binding="{Binding Path=Value}" Width="1*" Header="{loc:Translate Default='Value to search for'}" />
                </DataGrid.Columns>                
            </DataGrid>
            
            <Button Grid.Row="1" Margin="5" Padding="3" Content="{loc:Translate Default='Delete'}" 
                    Width="80" HorizontalAlignment="Right" Command="{Binding Path=DeleteCommand}"/>            
        </Grid>
        
        
        <!-- Right pane for entering values -->
        <Grid Grid.Row="0" Grid.Column="1">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            
            <!-- Raw text input -->
            <ContentControl Grid.Row="0" Margin="20">
                <StackPanel Orientation="Vertical">
                    <TextBlock Text="{loc:Translate Default='Enter the text value to search for:'}" Margin="5" />
                    <TextBox Margin="5" Text="{Binding Path=TextValue, Mode=TwoWay}" />
                </StackPanel>
                <ContentControl.Style>
                    <Style TargetType="ContentControl">
                        <Setter Property="Visibility" Value="Collapsed" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=VisibleControlID, Mode=OneWay}" Value="1">
                                <Setter Property="Visibility" Value="Visible" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ContentControl.Style>
            </ContentControl>

            <!-- Date picker -->
            <ContentControl Grid.Row="1" Margin="20">
                <StackPanel Orientation="Vertical">
                    <TextBlock Text="{loc:Translate Default='Enter the date value to search for'}" Margin="5" />
                    <DatePicker Margin="5" SelectedDate="{Binding Path=DateValue, Mode=TwoWay}"    />
                </StackPanel>
                <ContentControl.Style>
                    <Style TargetType="ContentControl">
                        <Setter Property="Visibility" Value="Collapsed" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=VisibleControlID}" Value="3">
                                <Setter Property="Visibility" Value="Visible" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ContentControl.Style>
            </ContentControl>
            
            <!-- Combo Box selection -->
            <ContentControl Grid.Row="2" Margin="20">
                <StackPanel Orientation="Vertical">
                    <TextBlock Text="{loc:Translate Default='Enter the value to search for'}" Margin="5" />
                    <ComboBox Margin="5" ItemsSource="{Binding Path=ResultTypes, Mode=OneWay}" 
                              SelectedValue="{Binding Path=ResultValue, Mode=TwoWay}" >
                    </ComboBox>
                </StackPanel>
                <ContentControl.Style>
                    <Style TargetType="ContentControl">
                        <Setter Property="Visibility" Value="Collapsed" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=VisibleControlID}" Value="2">
                                <Setter Property="Visibility" Value="Visible" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ContentControl.Style>
            </ContentControl>
            
            <!-- Final Library Filter -->
            <GroupBox Header="{loc:Translate Default='Filter Settings'}" Grid.Row="3" FontWeight="Bold" 
                      Margin="5" Padding="5">
                <DataGrid x:Name="uxFilterDG" AutoGenerateColumns="False"
                      CanUserAddRows="False" CanUserDeleteRows="False" CanUserResizeRows="False"
                      SelectionMode="Single" IsReadOnly="True"  CanUserReorderColumns="False"                            
                      ItemsSource="{Binding Path=FilterItems}" HeadersVisibility="None">
                    <DataGrid.Columns>
                        <DataGridTextColumn Width="1*" Binding="{Binding Path=Key}" />
                        <DataGridTextColumn Width="1*" Binding="{Binding Path=Value}" FontWeight="Normal" />
                    </DataGrid.Columns>
                </DataGrid>                
            </GroupBox>                                
        </Grid>
        
        <!-- Bottom panel of primary buttons -->
        <StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal">
            <Button Margin="5" Padding="3" Content="{loc:Translate Default='Filter games'}"
                     Width="80" Command="{Binding Path=SetFilterCommand}"/>
            <Button Margin="5" Padding="3" Content="{loc:Translate Default='Cancel'}"
                    Width="80" Command="{Binding Path=CancelCommand}"/>
        </StackPanel>                           
    </Grid>
</Window>
